﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using GMAC.ReportingSystem.Business.Entities;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace GMAC.ReportingSystem.Paginas
{
    public partial class ReportDetalledelaEscalera : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Se verifica que el usuario haya iniciado sesión
            if (!User.Identity.IsAuthenticated || Session["User"] == null)
            {
                System.Web.Security.FormsAuthentication.RedirectToLoginPage();
                return;
            }
            if (IsPostBack) return;
            Initialize();
            ValidateSecurity();

           
        }
        public void Initialize()
        {
            if (!this.IsPostBack)
            {
                grvStatus.DataSource = GenerateDataTablePruebaStatus();
                grvStatus.DataBind();

                grvProductType.DataSource = GenerateDataTablePrueba();
                grvProductType.DataBind();

                ddlProductType.DataSource = GenerateDataTablePrueba();
                ddlProductType.DataValueField = "AccountTypeID";
                ddlProductType.DataTextField = "ProductName";
                ddlProductType.DataBind();
                this.ddlProductType.Items.Insert(0, new ListItem("Select...", String.Empty));

                this.ddlBank.Items.Add(new ListItem("Venezuela", "1"));
                this.ddlBank.Items.Add(new ListItem("Banesco", "2"));
                this.ddlBank.Items.Insert(0, new ListItem("All...", String.Empty));

        
                this.ddlPastDueDay.Items.Add(new ListItem("<=120", "0"));
                this.ddlPastDueDay.Items.Add(new ListItem(">120", "1"));
                this.ddlPastDueDay.Items.Insert(0, new ListItem("All...", String.Empty));

                
                
                foreach (int i in Enum.GetValues(typeof(GeneralEnumTypes.TypeQuery)))
                {
                    this.ddlType.Items.Add(new ListItem(Enum.GetName(typeof(GeneralEnumTypes.TypeQuery), i).ToString().Replace('_', ' '), i.ToString()));

                }
                this.ddlType.Items.Insert(0, new ListItem("Select...", String.Empty));

                txtRDateSearch.Text = DateTime.Now.ToString("dd/MM/yyyy");            
                
                


            }
        }
        private void ValidateSecurity()
        {
            //var beEntities = ((User)Session["User"]).Role.Security.GetEntitySecurity("User");
            //if (beEntities == null) return;
            //if (!beEntities.CanRead)
            //{
            //    grvUsers.Visible = false;
            //    btnModify.Visible = false;
            //    btnDelete.Visible = false;
            //    pnlSearch.Visible = false;
            //}
            //if (!beEntities.CanWrite)
            //{
            //    btnSave.Visible = false;
            //}
            //if (!beEntities.CanInsert)
            //{
            //    btnNew.Visible = false;
            //    btnCancel.Visible = false;
            //    pnlEdit.Visible = false;
            //}
            //if (!beEntities.CanDelete)
            //{
            //    btnDelete.Visible = false;
            //}
        }

        protected void imgBuscarReg_Click(object sender, ImageClickEventArgs e)
        {
            //Codigo para reecorrer el gridview de productos
            //foreach (GridViewRow row in grvProductType.Rows)
            //{
            //if (((CheckBox)row.Cells[0].FindControl("chkSelected")).Checked == true)
            //{
            //    //aqui se va consruyendo el parametro del Producto
            //}

            //}
            
            //List<ReportParameter> parametros = new List<ReportParameter>();
            //parametros.Add(new ReportParameter("Type", this.ddlType.SelectedValue));
            //parametros.Add(new ReportParameter("EstatusStr", this.ddlEstatus.SelectedItem.Text));
            //parametros.Add(new ReportParameter("Placa", this.txtPlaca.Text));
            //if (String.IsNullOrEmpty(this.ddlCliente.SelectedValue))
            //{
            //    parametros.Add(new ReportParameter("IdCliente", "0"));
            //}
            //else
            //{
            //    parametros.Add(new ReportParameter("IdCliente", this.ddlCliente.SelectedValue));
            //}
            //parametros.Add(new ReportParameter("Cliente", this.ddlCliente.SelectedItem.Text));
            //string FechaDesde = null;
            //if (string.IsNullOrEmpty(this.txtFechaDesde.Text))
            //{
            //    parametros.Add(new ReportParameter("FechaDesde", FechaDesde));
            //}
            //else
            //{
            //    parametros.Add(new ReportParameter("FechaDesde", this.txtFechaDesde.Text));
            //}
            //string FechaHasta = null;
            //if (string.IsNullOrEmpty(this.txtFechaHasta.Text))
            //{
            //    parametros.Add(new ReportParameter("FechaHasta", FechaHasta));
            //}
            //else
            //{
            //    parametros.Add(new ReportParameter("FechaHasta", this.txtFechaHasta.Text));
            //}

            //string asignacion = null;
            //if (!String.IsNullOrEmpty(this.txtAsignacion.Text.Trim()))
            //{
            //    asignacion = this.txtAsignacion.Text;
            //}
            //parametros.Add(new ReportParameter("Asignacion", asignacion));

            //string localizacion = null;
            //if (!String.IsNullOrEmpty(this.txtLocGeografica.Text.Trim()))
            //{
            //    localizacion = this.txtLocGeografica.Text;
            //}
            //parametros.Add(new ReportParameter("LocalizacionGeo", localizacion));


            //this.rptwReportes.Style.Add("margin-bottom", "26px");
            //this.rptwReportes.ServerReport.ReportPath = "/ReportSIT/rptServicios";
            //this.rptwReportes.ProcessingMode = ProcessingMode.Remote;
            //this.rptwReportes.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["REPORT_SERVER"].ToString());
            //this.rptwReportes.ServerReport.SetParameters(parametros);
            Image1.Visible = true;
        }

        protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlType.SelectedValue == ((int)GeneralEnumTypes.TypeQuery.Single).ToString())
            {
                ddlProductType.Visible = true;
                rfvProductType.Visible = true;
                pnlProductType.Visible = false;
            }
            else
            {
                if (ddlType.SelectedValue == ((int)GeneralEnumTypes.TypeQuery.Consolidate).ToString())
                {
                    ddlProductType.Visible = false;
                    rfvProductType.Visible = false;
                    pnlProductType.Visible = true;
                }
                else
                {
                    ddlProductType.Visible = true;
                    rfvProductType.Visible = true;
                    pnlProductType.Visible = false;
                }
            }
        }
        private DataTable GenerateDataTablePrueba()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("AccountTypeID", typeof(string));
            dt.Columns.Add("ProductName", typeof(string));
            DataRow rowdt;
            rowdt = dt.NewRow();
            rowdt[0] = "2";
            rowdt[1] = "GMAC";
            dt.Rows.Add(rowdt);
            rowdt = dt.NewRow();
            rowdt[0] = "3";
            rowdt[1] = "Banco de Venezuela";
            dt.Rows.Add(rowdt);
            rowdt = dt.NewRow();
            rowdt[0] = "4";
            rowdt[1] = "Otro Producto";
            dt.Rows.Add(rowdt);

            return dt;

        }
        private DataTable GenerateDataTablePruebaStatus()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("AccountStatusID", typeof(string));
            dt.Columns.Add("StatusName", typeof(string));
            DataRow rowdt;
            rowdt = dt.NewRow();
            rowdt[0] = "1";
            rowdt[1] = "Active";
            dt.Rows.Add(rowdt);
            rowdt = dt.NewRow();
            rowdt[0] = "17";
            rowdt[1] = "Insurance Claim";
            dt.Rows.Add(rowdt);
            rowdt = dt.NewRow();
            rowdt[0] = "4";
            rowdt[1] = "Transferred to possible loss";
            dt.Rows.Add(rowdt);

            return dt;

        }


    }
}
